import 'package:earclean/app/request/http_request.dart';
import 'package:earclean/app/routes/app_pages.dart';
import 'package:earclean/app/util/Yue_utils.dart';
import 'package:get/get.dart';

class InfoController extends GetxController {
  //TODO: Implement InfoController

  final count = 0.obs;
  late int id;

  final info = {}.obs;
  final bannerList = [].obs;
  final serviceProjects = [].obs;
  final userComments = [].obs;
  final infoStr = ''.obs;
  final nickname = ''.obs;
  final pfr = ''.obs;
  final userCommentNum = ''.obs;

  @override
  void onInit() {
    id = Get.arguments['id'];
    loadData();

    super.onInit();
  }

  loadData() async {
    final result = await HttpRequest.get('https://iamz.jiliol.net/users.json');
    if (result.result) {
      List map = result.data ?? [];
      if (map.isNotEmpty) {
        map.forEach((element) {
          if (element['id'] == id) {
            info.value = element;
            infoStr.value = element['info'] ?? "";
            nickname.value = element['nickname'] ?? "";
            userCommentNum.value = (element['userCommentNum'] ?? "").toString();
            pfr.value = element['pfr'] ?? "";
            bannerList.value = element['album'] ?? [];
            serviceProjects.value = element['serviceProjects'] ?? [];
            userComments.value = element['userComments'] ?? [];
            return;
          }
        });
      }
    }
  }

  //  去评论
  toUserComments() {
    Get.toNamed(Routes.PINGJIA, arguments: {
      "list": userComments.value,
    });
  }

  // 预约
  toYue(Map item) {
    YueUtils.yuyue({
      'id': item['id'],
      'title': item['projectName'],
      'pic': item['projectPic'],
      'timer': item['projectTimer'],
      'price': item['projectPrice'],
    });
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {}
  void increment() => count.value++;
}
